package com.shudai.largescreen.service.impl;

import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.github.pagehelper.PageHelper;
import com.shudai.largescreen.mapper.RegionMapper;
import com.shudai.largescreen.pojo.dto.AreaAchievementDto;
import com.shudai.largescreen.pojo.vo.*;
import com.shudai.largescreen.service.RegionService;
import com.shudai.largescreen.util.DateQuery;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.stream.Collectors;

@Service
@RequiredArgsConstructor
@Slf4j
public class RegionServiceImpl implements RegionService {

    private final RegionMapper regionMapper;

    @Override
    public AllRegionCity getAllRegionCity() {
        String all = regionMapper.findAllRegionCity();
        //总利润
        ItemsVal itemsVal = new ItemsVal();
        itemsVal.setCompanyGrossProfit("0.8181");
        itemsVal.setCostOfTransportation("12");
        itemsVal.setCostOfMaterial("12");
        itemsVal.setOfflinePromotionCost("91");
        itemsVal.setOlinePromotionCost("20");

        AllRegionCity allRegionCity = new AllRegionCity();
        allRegionCity.setTotal(all);
        allRegionCity.setItemsVal(itemsVal);

        return allRegionCity;
    }

    @Override
    public RegionCity getWeakRegionCity(String area, String district) {

        //本周第一天
       String weekStart = DateQuery.getWeekStart();
//        String weekStart = "2022-01-10 00:00:00";

        //1.具有转换功能的对象
        DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");

        //3.LocalDate发动，将字符串转换成  df格式的LocalDateTime对象，的功能
        LocalDateTime LocalTime = LocalDateTime.parse(weekStart, df);
        System.out.println("String类型的时间转成LocalDateTime：" + LocalTime);



        //查询每周数量
        List<NumberAmount> cityOrderRate = regionMapper.findVistWeakRate(area, district, LocalTime);


        Date[] weekDay = new Date[0];
        try {
            weekDay = DateQuery.getWeekDay();
        } catch (ParseException e) {
            throw new RuntimeException(e);
        }

        for (int i = 0; i < weekDay.length; i++) {
            System.out.println("传递： " + weekDay[i]);
        }
        List<NumberAmount> experienceDayResList = new ArrayList<>(cityOrderRate);
        for (Date date : weekDay) {
            // 当前日期不存在则新增
            String dateStr = DateUtil.format(date, "dd");
            // 进行匹配
            if (!experienceDayResList.stream().filter(item -> dateStr.equals(item.getName())).findAny().isPresent()) {
                NumberAmount experienceDayRes = NumberAmount.builder()
                        .name(dateStr)
                        .data(0)
                        .build();
                experienceDayResList.add(experienceDayRes);
            }
        }

        List<NumberAmount> collect = experienceDayResList.stream().sorted(Comparator.comparing(NumberAmount::getName)).collect(Collectors.toList());

        for (int i = 0; i < collect.size(); i++) {
            collect.get(i).setName("星期" + ((i + 1)%7) + "");

        }
        List<String> week = DateQuery.week(collect.stream().map(NumberAmount::getName).collect(Collectors.toList()));
        for (int i = 0; i < week.size(); i++) {
            collect.get(i).setName(week.get(i));
        }

        for (NumberAmount numberAmount : collect) {
            System.out.println(numberAmount);
        }

        //已完成
        int sum = collect.stream().mapToInt(NumberAmount::getData).sum();
        RegionCity regionCity = new RegionCity();
        regionCity.setChartData(collect);
        regionCity.setTotal("10000");
        regionCity.setWait((Integer.parseInt(regionCity.getTotal()) - sum) + "");
        regionCity.setFinished(BigDecimal.valueOf(sum).divide(BigDecimal.valueOf(Long.parseLong(regionCity.getTotal())), 2, RoundingMode.HALF_UP));

        return regionCity;
    }

    @Override
    public RegionCity getWeakOrderCity(String area, String district) {
        //本周第一天
        String weekStart = DateQuery.getWeekStart();
//        String weekStart = "2022-10-01 00:00:00";

        //1.具有转换功能的对象
        DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");

        //3.LocalDate发动，将字符串转换成  df格式的LocalDateTime对象，的功能
        LocalDateTime LocalTime = LocalDateTime.parse(weekStart, df);
        System.out.println("String类型的时间转成LocalDateTime：" + LocalTime);


//        String vistWeak = regionMapper.findVistWeak(area,district,LocalTime);


        //查询每周数量
        List<NumberAmount> cityOrderRate = regionMapper.findOrderWeakRate(area, district, LocalTime);


        Date[] weekDay = new Date[0];
        try {
            weekDay = DateQuery.getWeekDay();
        } catch (ParseException e) {
            throw new RuntimeException(e);
        }

        for (int i = 0; i < weekDay.length; i++) {
            System.out.println("传递： " + weekDay[i]);
        }
        List<NumberAmount> experienceDayResList = new ArrayList<>(cityOrderRate);
        for (Date date : weekDay) {
            // 当前日期不存在则新增
            String dateStr = DateUtil.format(date, "dd");
            // 进行匹配
            if (!experienceDayResList.stream().filter(item -> dateStr.equals(item.getName())).findAny().isPresent()) {
                NumberAmount experienceDayRes = NumberAmount.builder()
                        .name(dateStr)
                        .data(0)
                        .build();
                experienceDayResList.add(experienceDayRes);
            }
        }

        List<NumberAmount> collect = experienceDayResList.stream().sorted(Comparator.comparing(NumberAmount::getName)).collect(Collectors.toList());


        for (int i = 0; i < collect.size(); i++) {
            collect.get(i).setName("星期" + ((i + 1)%7) + "");

        }
        List<String> week = DateQuery.week(collect.stream().map(NumberAmount::getName).collect(Collectors.toList()));
        for (int i = 0; i < week.size(); i++) {
            collect.get(i).setName(week.get(i));
        }

        for (NumberAmount numberAmount : collect) {
            System.out.println(numberAmount);
        }

        //已完成
        int sum = collect.stream().mapToInt(NumberAmount::getData).sum();
        RegionCity regionCity = new RegionCity();
        regionCity.setChartData(collect);
        regionCity.setTotal("10000");
        regionCity.setWait((Integer.parseInt(regionCity.getTotal()) - sum) + "");
        regionCity.setFinished(BigDecimal.valueOf(sum).divide(BigDecimal.valueOf(Long.parseLong(regionCity.getTotal())), 2, RoundingMode.HALF_UP));


        return regionCity;
    }

    @Override
    public List<AreaAchievementVo> getAreaAchievementCity(String province,
                                                          String region,
                                                          String teamName,
                                                          String startTime,
                                                          String status) {
        System.out.println("地区业绩总汇 province  "+province);
        //本月第一天
        // tODo
        if (StringUtils.isEmpty(status)){
           status = "1";
        }

        System.out.println("statusJK : "+status);
        if (status.equals("0")){
            List<AreaAchievementVo> areaAchievementVos = new ArrayList<>();
            return areaAchievementVos;
        }

        LocalDate someStart = null;
        LocalDate someEnd = null;
        LocalDate someStartLast = null;
        LocalDate someEndLast = null;
        if (StringUtils.isEmpty(startTime)) {
            String mothNow =  (DateTime.now() + "").split(" ")[0].split("-")[0] +(DateTime.now() + "").split(" ")[0].split("-")[1];
            String mothLast =  (DateTime.now() + "").split(" ")[0].split("-")[0] + (Integer.parseInt((DateTime.now() + "").split(" ")[0].split("-")[1])-1);
            //这月的
            someStart = DateQuery.getMothSomeStart(mothNow);
            someEnd = DateQuery.getMothSomeEnd(mothNow);
            //上月的
            someStartLast = DateQuery.getMothSomeStart(mothLast);
            someEndLast = DateQuery.getMothSomeEnd(mothLast);

        }


        if (StringUtils.isNotEmpty(startTime) && !startTime.substring(4).equals("01")){
            someStart = DateQuery.getMothSomeStart(startTime);
            someEnd = DateQuery.getMothSomeEnd(startTime);

            //上月的
            someStartLast = DateQuery.getMothSomeStart((Integer.parseInt(startTime)-1)+"");
            someEndLast = DateQuery.getMothSomeEnd((Integer.parseInt(startTime)-1)+"");
        }
        if (StringUtils.isNotEmpty(startTime) && startTime.substring(4).equals("01")){
            someStart = DateQuery.getMothSomeStart(startTime);
            someEnd = DateQuery.getMothSomeEnd(startTime);

            //上年的最后一个月的
            someStartLast = DateQuery.getMothSomeStart((Integer.parseInt(startTime)-89)+"");
            someEndLast = DateQuery.getMothSomeEnd((Integer.parseInt(startTime)-89)+"");
        }

        List<String> cityList = new ArrayList<>();

        if (StringUtils.isEmpty( province) && StringUtils.isEmpty(region)){
            province="广东省";
            //查询城市下所有区域
            cityList = regionMapper.findAllCity(province);
        }

        System.out.println(province);
        if (StringUtils.isNotEmpty( province)&& StringUtils.isEmpty(region)){
            province=province;
            //查询城市下所有区域
            cityList = regionMapper.findAllCity(province);
        }
        if  (StringUtils.isNotEmpty( province)&& StringUtils.isNotEmpty(region)){
            province = province;
            cityList.add(region);
        }

        //本周第一天
//        String weekStart = getWeekStart();
//        String weekStart = "2022-01-10 00:00:00";
//        startTime = "2020-01-10 00:00:00";

        //1.具有转换功能的对象
        DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");

        //3.LocalDate发动，将字符串转换成  df格式的LocalDateTime对象，的功能
        LocalDateTime startLocalTime = LocalDateTime.parse(someStart+" 00:00:00", df);
        LocalDateTime endLocalTime = LocalDateTime.parse(someEnd+" 00:00:00", df);

        LocalDateTime startLocalTimeLast = LocalDateTime.parse(someStartLast+" 00:00:00", df);
        LocalDateTime endLocalTimeLast = LocalDateTime.parse(someEndLast+" 00:00:00", df);

        List<AreaAchievementVo> areaAchievementVos = new ArrayList<>();
        for (String city : cityList) {

            AreaAchievementVo areaAchievementVo = new AreaAchievementVo();

            areaAchievementVo.setAreaName(province+"-"+city);
            areaAchievementVo.setStatus(1);
            //上个月
            // 上月第一天
//            String lastMoth = DateQuery.getLastMoth();

//            LocalDateTime lastMoths = LocalDateTime.parse("2019-10-10" + " 00:00:00", df);
//            LocalDateTime lastMoths = LocalDateTime.parse(lastMoth, df);
            //查进销商数量
            Integer totalDistributorNumber = regionMapper.findDistributorNumber(province,city,endLocalTime);

            //查询地区下进销商数 订单数 和总产出  startLocalTime.minusDays(times), startLocalTime,
            System.out.println(" 和总产出 ");
//            AreaAchievementVo vo = regionMapper.findDistributors(province, city,
//                    status, lastMoths, startLocalTime, teamName);

            AreaAchievementVo vo = regionMapper.findDistributors(province, city,
                    status, startLocalTime, endLocalTime, teamName);

            //客户增长率 本期周期统计总数-对比周期总数÷对比周期总数×100%


            //上一个月的 客户 2
            System.out.println(" 客户增长" );
            int areaAchievementDto = regionMapper.findNowMothss(province, city, status, startLocalTimeLast,endLocalTimeLast, teamName);

            //这个月 s 0
            int areaAchievementDtos = regionMapper.findNowMothss(province, city, status, startLocalTime, endLocalTime, teamName);

            //订单增长 上一个月 22
            System.out.println(" 订单增长" );
            int beforeOrderDto = regionMapper.findBeforeOrders(province, city, status,  startLocalTimeLast, endLocalTimeLast, teamName);

            //订单增长 这个月 11
            int nowOrderDto = regionMapper.findNowOrders(province, city, status, startLocalTime, endLocalTime, teamName);

            //客户增长
            BigDecimal totalNumber = new BigDecimal(0);
            if (areaAchievementDto != 0){
                //客户增长
                totalNumber =  ((new BigDecimal(areaAchievementDtos).subtract(new BigDecimal(areaAchievementDto))).divide(new BigDecimal(areaAchievementDto), 2, RoundingMode.HALF_UP));
                System.out.println(totalNumber);
            }
            if (areaAchievementDtos == 0){
                //客户增长
                totalNumber = new BigDecimal(-areaAchievementDto) ;

            }
            if (areaAchievementDto == 0){
                //客户增长
                totalNumber = new BigDecimal(areaAchievementDtos);
            }
            areaAchievementVo.setCustomerInc(totalNumber);
            //订单增长
            BigDecimal totalOrder = new BigDecimal(0);
            if (beforeOrderDto !=0){
                //客户增长
                totalOrder =  (new BigDecimal(nowOrderDto).subtract(new BigDecimal(beforeOrderDto ))).divide(new BigDecimal(beforeOrderDto), 2, RoundingMode.HALF_UP);

            }
            if (beforeOrderDto == 0){
                //客户增长
                totalOrder = new BigDecimal(nowOrderDto) ;

            }
            if (nowOrderDto == 0){
                //客户增长
                totalOrder = new BigDecimal(-beforeOrderDto);
            }
            areaAchievementVo.setOrderNumberInc(totalOrder);

            areaAchievementVo.setDistributorNumber(totalDistributorNumber+"");

            if (ObjectUtils.isNotEmpty(vo)){
                areaAchievementVo.setOrderNumber(vo.getOrderNumber());
                areaAchievementVo.setTotalProduce(vo.getTransactionAmount());

//                areaAchievementVo.setTotalProduce(vo.getTotalProduce());
            }else {
                areaAchievementVo.setOrderNumber(0);
                areaAchievementVo.setTotalProduce(0);
            }

            areaAchievementVos.add(areaAchievementVo);
        }

        List<AreaAchievementVo> collect = areaAchievementVos.stream().sorted(Comparator.comparingInt(AreaAchievementVo::getTotalProduce).reversed()).collect(Collectors.toList());

        return collect;

    }


    @Override
    public List<ReCustomerVo> getReCustomerIOrder(String area, String district) {

        //已购未返单
//        PageHelper.startPage(0,10);
        List<ReCustomerVo> reCustomerVoList = regionMapper.getReCustomerIOrder(area, district);
        List<ReCustomerVo> collect = reCustomerVoList.stream().filter(x -> x.getTotal() == 0).collect(Collectors.toList());
        for (ReCustomerVo reCustomerVo : collect) {
            reCustomerVo.setBelong(reCustomerVo.getProvince() + "-" + reCustomerVo.getCity());
            reCustomerVo.setStatus("0");
            reCustomerVo.setCustomerType("0");
            reCustomerVo.setImg(reCustomerVo.getImg());
        }
        return collect;
    }

    @Override
    public List<ReCustomerVo> getReCustomerTime(String area, String district) {
        //计算平均返单时间
        System.out.println("asibkn1o");
//        PageHelper.startPage(0,10);
        // TODO:sql报错 getReCustomerTime
        List<ReCustomerVo> reCustomerVoList = regionMapper.findReCustomerTime(area, district);

        //1.具有转换功能的对象
        DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyyMMdd");
        Integer time = 0;
        Integer total = 0;
        //3.LocalDate发动，将字符串转换成  df格式的LocalDateTime对象，的功能
        for (int i = 0; i < reCustomerVoList.size()-1; i++) {
            if (i % 2 == 0) {
                if (reCustomerVoList.get(i + 1).getSeqnum() - reCustomerVoList.get(i).getSeqnum() == 1) {
                    if (i % 2 == 0) {
                        time += Integer.valueOf(df.format(reCustomerVoList.get(i + 1).getLastOrderTime())) - Integer.valueOf(df.format(reCustomerVoList.get(i).getLastOrderTime()));
                        total++;
                    }
                }
            }

        }
        List<ReCustomerVo> reCustomerVos = new ArrayList<>();
        if (total != 0) {
            //平均返单时间
            Integer times = time / total;
            //查询每个用户最大的返单时间
            List<ReCustomerVo> reCustomerIOrder = regionMapper.getReCustomerIOrder(area, district);
//            List<ReCustomerVo> collect = reCustomerIOrder.stream().filter(x -> x.getTotal() == 0).collect(Collectors.toList());
            reCustomerVos = reCustomerIOrder.stream().filter(x -> x.getLastOrderTime().minusDays(times).isBefore(LocalDateTime.now())).collect(Collectors.toList());
            for (ReCustomerVo reCustomerVo : reCustomerVos) {
                reCustomerVo.setBelong(reCustomerVo.getProvince()+"-"+reCustomerVo.getCity());
                reCustomerVo.setStatus("0");
                reCustomerVo.setCustomerType("0");
                reCustomerVo.setImg(reCustomerVo.getImg());
            }
        }

        System.out.println("翻单时间： "+time);
        System.out.println("翻单时间： "+total);
        return reCustomerVos;
    }


    @Override
    public Map<String,Object> getRegionRank(String province, String region) {

        List<String> cityList = new ArrayList<>();

        if (StringUtils.isEmpty( province) && StringUtils.isEmpty(region)){
            province="广东省";
            //查询城市下所有区域
            cityList = regionMapper.findCity(province);
        }

        System.out.println(province);
        if (StringUtils.isNotEmpty( province)&& StringUtils.isEmpty(region)){
//            province=province;
            //查询城市下所有区域
            cityList = regionMapper.findCity(province);
        }
        if  (StringUtils.isNotEmpty( province)&& StringUtils.isNotEmpty(region)){
            province = province;
            cityList.add(region);
        }

        //1.具有转换功能的对象
        DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");

        //3.LocalDate发动，将字符串转换成  df格式的LocalDateTime对象，的功能
        LocalDateTime startLocalTime = LocalDateTime.parse( DateQuery.getMothStart(), df);
//        LocalDateTime startLocalTime = LocalDateTime.parse( "2020-10-10 00:00:00", df);
        Map<String,Object> chartDataCitys = new HashMap<>();
        List<Map<String,Object>> chartData = new ArrayList<>();
        chartDataCitys.put("area",province);

        ChartDataCityVo regionRank = regionMapper.findRegionRank1(province, startLocalTime);

        if (CollectionUtils.isNotEmpty(cityList)){
            for (String s : cityList) {

                ChartDataCityVo cityOrderMoths = regionMapper.findRegionRank(province, s,startLocalTime);

                if (ObjectUtils.isNotEmpty(cityOrderMoths) &&ObjectUtils.isNotEmpty(regionRank) ){

                    Map<String, Object> obj = new HashMap<>();
                    obj.put("name", s);
                    obj.put("data", new BigDecimal(cityOrderMoths.getDate()).divide(new BigDecimal(regionRank.getDate()),2, RoundingMode.HALF_UP));
                    chartData.add(obj);

                }else {
                    Map<String, Object> obj = new HashMap<>();
                    obj.put("name", s);
                    obj.put("data", new BigDecimal(0));
                    chartData.add(obj);
                }

            }
        }else {
            if(ObjectUtils.isNotEmpty(regionRank)){
                Map<String, Object> obj = new HashMap<>();
                obj.put("name", province);
                if ( null != regionRank.getDate() ){
                    obj.put("data", new BigDecimal(regionRank.getDate()));
                }else {
                    obj.put("data", new BigDecimal(0));
                }
                chartData.add(obj);
            }
           else {
                Map<String, Object> obj = new HashMap<>();
                obj.put("name", province);
                obj.put("data", new BigDecimal(0));
                chartData.add(obj);

            }


        }


        chartDataCitys.put("chartData", chartData);

        return chartDataCitys;

    }


    @Override
    public   Map<String,Object> getConversionRate(String province, String region, String startData) {

        //1.具有转换功能的对象
        DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");

        //3.LocalDate发动，将字符串转换成  df格式的LocalDateTime对象，的功能
        LocalDateTime startLocalTime = null;
        LocalDateTime endLocalTime = null ;
        if (StringUtils.isEmpty(startData) ){
            startLocalTime = LocalDateTime.parse( DateQuery.getMothStart(), df);
//            startLocalTime = LocalDateTime.parse( "2020-10-10 00:00:00", df);
            endLocalTime = LocalDateTime.now();
        }else {
            startLocalTime = LocalDateTime.parse(DateQuery.getMothSomeStart(startData)+" 00:00:00",df);
            endLocalTime = LocalDateTime.parse(DateQuery.getMothSomeEnd(startData)+" 23:00:00",df);
        }
//        if (StringUtils.isNotEmpty(startData) && StringUtils.isEmpty(endData)){
//            startLocalTime = LocalDateTime.parse( startData, df);
//            endLocalTime = LocalDateTime.now();
//        }



        List<String> cityList = new ArrayList<>();
        if (StringUtils.isEmpty( province)&& StringUtils.isEmpty(region)){
            province="广东省";
            //查询城市下所有区域
            cityList = regionMapper.findCity(province);
        }
        if (StringUtils.isNotEmpty( province)&& StringUtils.isEmpty(region)){
            //查询城市下所有区域
            province = province;
            cityList = regionMapper.findCity(province);
        }
        if  (StringUtils.isNotEmpty( province)&& StringUtils.isNotEmpty(region)){
            province = province;
            cityList.add(region);
        }




        Map<String,Object> chartDataCitys = new HashMap<>();
        List<Map<String,Object>> chartData = new ArrayList<>();

        for (String s: cityList) {

            //查询拜访用户量 size
            ChartDataCityVo vo = regionMapper.findConversion(province,s,startLocalTime,endLocalTime);
            ChartDataCityVo vo1 = regionMapper.findUserRe(province,s,startLocalTime,endLocalTime);
            //查询这些用户下单的人
            ChartDataCityVo vos = regionMapper.findOrders(province,s,startLocalTime,endLocalTime);

            if (vos != null){
                System.out.println( "+++++" + vos);
            }


            if ( vos != null  ){
                if (  ObjectUtils.isNotEmpty(vo1) || ObjectUtils.isNotEmpty(vo)){
                    int totalVisit = 0;
                    if (ObjectUtils.isNotEmpty(vo1) && ObjectUtils.isNotEmpty(vo)){
                        totalVisit = vo.getDate()+vo1.getDate();
                    }
                    if (ObjectUtils.isNotEmpty(vo1) && ObjectUtils.isEmpty(vo)){
                        totalVisit = vo1.getDate();
                    }
                    if (ObjectUtils.isEmpty(vo1) && ObjectUtils.isNotEmpty(vo)){
                        totalVisit = vo.getDate();
                    }


                    System.out.println(vos +" 拜访 "+ totalVisit);
                    Map<String, Object> obj = new HashMap<>();
                    obj.put("name", s);
                    obj.put("data1", new BigDecimal(vos.getDate()).divide(new BigDecimal(totalVisit),2, RoundingMode.HALF_UP));
                    obj.put("data2", totalVisit);
                    chartData.add(obj);

                }
            }else {
                if (ObjectUtils.isNotEmpty(vo1) || ObjectUtils.isNotEmpty(vo)){
                    int totalVisit = 0;
                    if (ObjectUtils.isNotEmpty(vo1) && ObjectUtils.isNotEmpty(vo)){
                        totalVisit = vo.getDate()+vo1.getDate();
                    }
                    if (ObjectUtils.isNotEmpty(vo1) && ObjectUtils.isEmpty(vo)){
                        totalVisit = vo1.getDate();
                    }
                    if (ObjectUtils.isEmpty(vo1) && ObjectUtils.isNotEmpty(vo)){
                        totalVisit = vo.getDate();
                    }


                    System.out.println(vos +" "+ totalVisit);
                    Map<String, Object> obj = new HashMap<>();
                    obj.put("name", s);
                    obj.put("data1", new BigDecimal(0));
                    obj.put("data2", totalVisit);
                    chartData.add(obj);
                }else {
                    Map<String, Object> obj = new HashMap<>();
                    obj.put("name", s);
                    obj.put("data1", new BigDecimal(0));
                    obj.put("data2", 0);
                    chartData.add(obj);
                }

            }

        }

        List<Map<String, Object>> data1 = chartData.stream().sorted(Comparator.comparing((Map<String,Object> chart)->(BigDecimal) chart.get("data1")).reversed()).collect(Collectors.toList());

        chartDataCitys.put("chartData", data1);

        return chartDataCitys;

    }


    @Override
    public Map<String, Object> getDistributorGrade(String province, String city) {
        if (StringUtils.isEmpty(province) && StringUtils.isEmpty(city)) {
            province = "广东省";
            city = "深圳市";
        }
        Map<String,Object> hashMap = new HashMap<>();
        hashMap.put("s",0.12);
        hashMap.put("a",0.18);
        hashMap.put("b",0.3);
        hashMap.put("c",0.4);
        hashMap.put("areaName",province+"-"+city);
        hashMap.put("total",200);


        return hashMap;
    }
}
